"""
urls.py

URL dispatch route mappings and error handlers

"""

from flask import render_template

from application import app
from application.views import index, cron, view

## URL dispatch rules
# App Engine warm up handler
# See http://code.google.com/appengine/docs/python/config/appconfig.html#Warming_Requests
app.add_url_rule('/_ah/warmup', 'warmup', view_func=index.warmup)

# Index page
app.add_url_rule('/', 'index', view_func=index.index)
# authed page
app.add_url_rule('/authed', 'authed', view_func=index.authed)
# admin page
app.add_url_rule('/admin', 'admin', view_func=index.admin)

# test
app.add_url_rule('/test', 'test', view_func=index.test)

# cron and queue
app.add_url_rule('/cron_fetch_all', 'cron_fetch_all', view_func=cron.cron_fetch_all)
app.add_url_rule('/q_fetch_channel', 'q_fetch_channel', view_func=cron.q_fetch_channel, methods=['GET', 'POST'])
app.add_url_rule('/cron_clean_old', 'cron_clean_old', view_func=cron.cron_clean_old)
app.add_url_rule('/cron_invalid_maggic', 'cron_invalid_maggic', view_func=cron.cron_invalid_maggic)
app.add_url_rule('/q_mark_as_read', 'q_mark_as_read', view_func=cron.q_mark_as_read, methods=['GET', 'POST'])

# Start here!
app.add_url_rule('/view', 'view', view_func=view.view)
app.add_url_rule('/subscribe', 'subscribe', view_func=view.subscribe)
app.add_url_rule('/folders', 'folders', view_func=view.folders)

# Index
#app.add_url_rule('/index', 'index', view_func=index.index)

# Wishlist
#app.add_url_rule('/wishlist', 'wishlist', view_func=wishlist.wishlist)

# New_wish
#app.add_url_rule('/new_wish', 'new_wish', view_func=wishlist.new_wish, methods=['POST'])

# Del_wish
#app.add_url_rule('/del_wish', 'del_wish', view_func=wishlist.del_wish)

# GTD
#app.add_url_rule('/gtd', 'gtd', view_func=gtd.gtd)

# New_Gtd
#app.add_url_rule('/new_gtd', 'new_gtd', view_func=gtd.new_gtd, methods=['POST'])

# Del_Gtd
#app.add_url_rule('/del_gtd', 'del_gtd', view_func=gtd.del_gtd)

# Del_Gtd_ajax
#app.add_url_rule('/_del_gtd', '_del_gtd', view_func=gtd._del_gtd)

# Say hello
#app.add_url_rule('/hello/<username>', 'say_hello', view_func=view.say_hello)

# Examples list page
#app.add_url_rule('/examples', 'list_examples', view_func=view.list_examples)

# Add new example via web form
#app.add_url_rule('/example/new', 'new_example', view_func=view.new_example, methods=['GET', 'POST'])

# Contrived admin-only view example
#app.add_url_rule('/admin_only', 'admin_only', view_func=view.admin_only)



## Error handlers
# Handle 404 errors
#@app.errorhandler(404)
#def page_not_found(e):
#    return render_template('404.html'), 404

# Handle 500 errors
#@app.errorhandler(500)
#def server_error(e):
#    return render_template('500.html'), 500

